<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Map" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: DMLYS
  Date: 2019/7/16
  Time: 13:42
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>input page</title>
</head>
<body>
<%--为什么要使用spring的form标签
1. 可以快速的开发出表单页面, 而且可以更方便的信息回显
2. 注意, springmvc 默认认为表单需要回显(而第一次时,请求域中没有要回显的对象信息) 会报错, --%>
<%--推荐使用绝对路径,否则在某些请求回出现相对路径异常的问题--%>
<form:form action="${pageContext.request.contextPath}/emp" method="POST" modelAttribute="employee">
    <%--    PATH属性对应html标签的name属性--%>
    <c:if test="${employee.id ==null}">
        LastName: <form:input path="lastName"></form:input>
    </c:if> <c:if test="${employee.id !=null}">
    <form:hidden path="id"></form:hidden>
    <input type="hidden" name="_method" value="PUT">

</c:if>
    <br>
    Email:<form:input path="email"></form:input>
    <br>
    <%
        Map<String, Object> genders = new HashMap<>();
        genders.put("男", "男");
        genders.put("女", "女");
        request.setAttribute("genders", genders);//放在请求域中,才能让radiobuttons访问到
    %>
    Gender:<form:radiobuttons path="gender" items="${genders}"></form:radiobuttons><br>
    Departments:<form:select path="department.id" items="${departments}" itemLabel="departmentName"
                             itemValue="id"></form:select><br>

    <input type="submit" value="Submit">
</form:form>

</body>
</html>
